<%--
 *  File:    AuthorityEntity.jsp
 *  @Author: Langerwang 
 *  Date:    2001/11/19
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc" %>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
    //init param
    Category cat = Category.getInstance("jsp.AuthorityEntity");
    String strModuleName = "UPM";
    String privilegeCode = "Z0203,L404";
%>


<%
    HashMap userinfo = session.getAttribute("userinfo") == null ? (new HashMap()) :
            (HashMap) session.getAttribute("userinfo");
    HashMap centerorginfo = session.getAttribute("centerorginfo") == null ? (new HashMap()) :
            (HashMap) session.getAttribute("centerorginfo");
    boolean bIsCenterOrg = false;

    if (userinfo.get("orgid") != null && centerorginfo.get("orgid") != null
            && ((Integer) centerorginfo.get("orgid")).equals((Integer) userinfo.get("orgid")))
        bIsCenterOrg = true;

    boolean disabled = true;
    if (userinfo.get("isprimaryadmin") != null && (userinfo.get("isprimaryadmin").toString()).equals("Y"))
        disabled = false;

    String strpccode = (String) request.getParameter("thepccode");
    if (strpccode == null)
        strpccode = "";
    else
        pageContext.setAttribute("pccode",strpccode);
    cat.info("the pccode is " + strpccode);
%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
    <title></title>
    <PageFlow:CheckPageFlow pageName="authorityentity"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
    <script language="JavaScript" src="../../css/<%= strLanguageCode %>/script.js"></script>
        <script language = "JavaScript" src = "../../js/FuncLib.js" ></script>
</head>

<script language="JavaScript">

function globalpccodechange()
{
    parent.down.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
    document.pccodechange.thegroupid.disabled = true;
    document.params.theuserid.disabled = false;
    document.pccodechange.theentitytype.value = "p";
    document.pccodechange.thepccode.value = document.params.pccode.value;
    isRunning = true;
    document.pccodechange.submit();
}

function orgcodechange()
{
    parent.down.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
    document.params.thegroupid.options[0].selected = true;
    if (document.params.theorgid.value == -1000)
    {
        document.params.thegroupid.disabled = false;
        document.params.theuserid.disabled = false;
        document.pccodechange.theentitytype.value = "p";
    }
    else
    {
        if (document.params.theuserid.value != -1000)
        {
            document.pccodechange.theentitytype.value = "u";
        }
        else
        {
            if (document.params.thegroupid.value != -1000)
            {
                document.pccodechange.theentitytype.value = "g";
            }
            else
                if ((document.params.pccode.value == 99) &&
                    (document.params.theorgid.value != "<%=JspHelper.filterNull( userinfo.get("orgid") )%>"))
                {
                    document.pccodechange.theentitytype.value = "so";
                }
                else
                {
                    document.pccodechange.theentitytype.value = "to";
                }
        }
    }
    if (document.params.theorgid.value == "<%=JspHelper.filterNull( userinfo.get("orgid") )%>")
    {
        document.params.thegroupid.disabled = false;
        document.params.theuserid.disabled = false;
    }
    else
    {
        document.params.thegroupid.disabled = true;
        document.params.theuserid.disabled = true;
    }
}

function usergroupchange()
{
    parent.down.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
    document.pccodechange.thegroupid.disabled = false;
    document.pccodechange.thegroupid.value = document.params.thegroupid.value;
    if (document.params.thegroupid.value != -1000)
        document.pccodechange.theentitytype.value = "g";
    else
    {
        document.pccodechange.thegroupid.disabled = true;
        if (document.params.theorgid.value == -1000)
        {
            document.params.thegroupid.disabled = false;
            document.params.theuserid.disabled = false;
            document.pccodechange.theentitytype.value = "p";
        }
        else if ((document.params.pccode.value == 99) &&
                 (document.params.theorgid.value != "<%=JspHelper.filterNull( userinfo.get("orgid") )%>"))
        {
            document.pccodechange.theentitytype.value = "so";
        }
        else
            document.pccodechange.theentitytype.value = "to";
    }
    document.pccodechange.thepccode.value = document.params.pccode.value;
    document.pccodechange.theorgid.value = document.params.theorgid.value;
    isRunning = true;
    document.pccodechange.submit();
}

function userchange()
{
    parent.down.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
    if (document.params.theuserid.value != -1000)
    {
        document.pccodechange.theentitytype.value = "u";
    }
    else
    {
        if (document.params.thegroupid.value != -1000)
            document.pccodechange.theentitytype.value = "g";
        else
            if ((document.params.pccode.value == 99) &&
                (document.params.theorgid.value != "<%=JspHelper.filterNull( userinfo.get("orgid") )%>"))
            {
                document.pccodechange.theentitytype.value = "so";
            }
            else
                document.pccodechange.theentitytype.value = "to";

    }
}

function showauthority()
{
    parent.down.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
    var thepccode = "";
    var theorgid = "";
    var thegroupid = "";
    var theuserid = "";
    var theentitytype = "";
    var flag = false;

    if (!<%=JspHelper.filterNull( bIsCenterOrg )%> && (document.params.theorgid.value == -1000 ||
                                 (document.params.theorgid.value == <%=JspHelper.filterNull( userinfo.get("orgid") )%> &&
                                  document.params.thegroupid.value == -1000 &&
                                  document.params.theuserid.value == -1000)))
        return;

    if (document.params.pccode.value != -1000)
        thepccode = "thepccode=" + document.params.pccode.value + "&";
    if (document.params.theorgid.value != -1000)
        theorgid = "theorgid=" + document.params.theorgid.value + "&";
    if (document.params.theuserid.value != -1000)
        theuserid = "theuserid=" + document.params.theuserid.value + "&";
    if (document.params.thegroupid.value != -1000)
        thegroupid = "thegroupid=" + document.params.thegroupid.value + "&";

    theentitytype = "theentitytype=" + document.pccodechange.theentitytype.value + "&";
<%--[SCRIPT]  var strhref = "Authority.jsp?thepccode="+document.params.pccode.value+"&theorgid="+document.params.theorgid.value+"&thegroupid="+document.params.thegroupid.value+"&theuserid="+document.params.theuserid.value+"&theentitytype="+document.pccodechange.theentitytype.value;  [SCRIPT]--%>
    var strhref = "Authority.jsp?<%= OvalTools.randomURL() %>&" + thepccode + theorgid + theuserid + thegroupid +
                  theentitytype


    parent.down.location.href = strhref;
}

</script>

<form name="pccodechange" method="post" action="AuthorityEntity.jsp?<%= OvalTools.randomURL() %>">
    <input type="hidden" name="pagename" value="authorityentity">
    <input type="hidden" name="actionname" value="initauthorityentity">
    <input type="hidden" name="thepccode">
    <input type="hidden" name="thegroupid">
    <input type="hidden" name="theorgid">
    <%
        String entitytype = (String) request.getParameter("theentitytype");
        if (entitytype == null)
        {
    %>
    <input type="hidden" name="theentitytype" value="p">
    <%
    } else
    {
    %>
    <input type="hidden" name="theentitytype" value=<%=JspHelper.filterNull( entitytype )%>>
    <%
        }
    %>
</form>

<body>
<table width="100%" cellspacing="0">
    <% //--------------------------------------  page location --%>
    <%@ include file="/inc/PageLocation.inc" %>
</table>

<%
    Vector globalpccodelist = (Vector) pageContext.getAttribute("globalpccodelist");
    if (globalpccodelist == null)
    {
        cat.info("the globalpccodelist is empty");
        globalpccodelist = new Vector();
    }
    cat.info("globalpccodelist is " + globalpccodelist);
    Vector orglist = (Vector) pageContext.getAttribute("orglist");
    if (orglist == null)
    {
        orglist = new Vector();
    }
    Vector usergrouplist = (Vector) pageContext.getAttribute("usergrouplist");
    if (usergrouplist == null)
    {
        usergrouplist = new Vector();
    }
    Vector userlist = (Vector) pageContext.getAttribute("userlist");
    if (userlist == null)
    {
        userlist = new Vector();
    }
    cat.info("get the date output from default action");
%>

<form name="params">
<table width="100%" cellspacing="0" border="0" cellpadding="0">
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
    <td class="summary_top" colspan="5"></td>
</tr>
<tr>
    <td width="13%" nowrap height="25" nowrap><%= label.getLabelName("L_PCCodeName") +
            label.getLabelName("L_Colon")%></td>
    <td width="18%" nowrap>
        <custom:selectdic property="pccode" onchange="globalpccodechange()" dictType="GlobalPCCode" valueCriteria="99,100-max" disabled="<%= disabled %>" />
        <%--<select name="pccode" onchange="globalpccodechange()" <%=JspHelper.filterNull( disabled )%>>
          <%
            cat.info("before show the globalpccodelist");
            boolean hasselected = false;
          %>
          <logic:iterate id="pccodelist" collection="<%= globalpccodelist %>">
          <%
            HashMap  mappccode = (HashMap)pageContext.getAttribute("pccodelist");
            if(mappccode == null)
              mappccode = new HashMap();
            if(strpccode.equals(mappccode.get("value").toString()))
            {
              selected = "selected";
              hasselected = true;
            }
            else
              selected = "";
          %>
          <option <%=JspHelper.filterNull(selected)%> value=<%=JspHelper.filterNull( mappccode.get("value"))%>><%=JspHelper.filterNull( (String)mappccode.get("valuename"))%></option>
          </logic:iterate>
          <%
            if(!hasselected)
            {
          %>
            <%=JspHelper.filterNull( "<option value=-1000 selected>---------</option>")%>
          <%
            }
          %>
        </select>--%>

    </td>
    <td width="10%" height="25" nowrap><%= label.getLabelName("L_OrgName") + label.getLabelName("L_Colon")%></td>
    <td width="20%" nowrap>
        <select name="theorgid" onchange="orgcodechange()">
            <%
                cat.info("before show the orglist");
                boolean hasselected = false;
                String selected = "";
                String strorgid = (String) request.getParameter("theorgid");
                if (strorgid == null)
                {
                    strorgid = "";
                }
                cat.info("the theorgid is " + strorgid);
            %>
            <option value=-1000 selected>---------</option>
            <logic:iterate id="theorglist" collection="<%= orglist %>">
                <%
                    HashMap maporg = (HashMap) pageContext.getAttribute("theorglist");
                    if (maporg == null)
                        maporg = new HashMap();
                    if (maporg.get("orgid") != null)
                        if (strorgid.equals(((Integer) maporg.get("orgid")).toString()))
                        {
                            selected = "selected";
                            hasselected = true;
                        } else
                            selected = "";
                %>
                <option <%=JspHelper.filterNull(selected)%> value=<%=JspHelper.filterNull( maporg.get("orgid").toString() )%>><%=JspHelper.filterNull( (String) maporg
                        .get("orgname"))%></option>
            </logic:iterate>
        </select>
    </td>
    <td width="47%">&nbsp;</td>
</tr>
<tr>
    <td width="13%" height="25" nowrap><%= label.getLabelName("L_UserGroupName") + label.getLabelName("L_Colon")%></td>
    <td width="18%" nowrap>
        <select name="thegroupid" onchange="usergroupchange()">
            <%
                cat.info("before show the grouplist");
                hasselected = false;
                String strgroupid = (String) request.getParameter("thegroupid");
                if (strgroupid == null)
                {
                    strgroupid = "";
                }
                cat.info("the groupid is " + strgroupid);
            %>
            <option value=-1000 selected>---------</option>
            <logic:iterate id="grouplist" collection="<%= usergrouplist %>">
                <%
                    HashMap mapusergroup = (HashMap) pageContext.getAttribute("grouplist");
                    if (mapusergroup == null)
                        mapusergroup = new HashMap();
                    if (mapusergroup.get("usergroupid") != null)
                        if (strgroupid.equals(((Integer) mapusergroup.get("usergroupid")).toString()))
                        {
                            selected = "selected";
                            hasselected = true;
                        } else
                            selected = "";
                %>
                <option <%=JspHelper.filterNull(selected)%> value=<%=JspHelper.filterNull( mapusergroup.get("usergroupid") )%>><%=JspHelper.filterNull( (String) mapusergroup
                        .get("usergroupname") )%></option>
            </logic:iterate>
        </select>
    </td>
    <td width="10%" height="25" nowrap><%= label.getLabelName("L_UserName") + label.getLabelName("L_Colon")%></td>
    <td width="20%" nowrap>
        <select name="theuserid" onchange="userchange()">
            <option value=-1000 selected>--------</option>
            <%
                cat.info("before show the userlist");
            %>
            <logic:iterate id="listuser" collection="<%= userlist %>">
                <%
                    HashMap mapuser = (HashMap) pageContext.getAttribute("listuser");
                    if (mapuser == null)
                        mapuser = new HashMap();
                %>
                <option value=<%=JspHelper.filterNull( mapuser.get("userid"))%>><%=JspHelper.filterNull( (String) mapuser.get("username"))%></option>
            </logic:iterate>
        </select>
    </td>
    <td width="47%"><a href="javascript:showauthority()">
        <img src="../../images/<%= strLanguageCode %>/go_fy.gif" border="0" style="border: 1 solid #000000"></a></td>
</tr>
<tr>
    <td colspan="5" class="summary_top"></td>
</tr>
</table>
</td>
</tr>
<script language="JavaScript">
    <%
if(entitytype != null)
{
  if(entitytype.equals("p"))
  {
    %>

    document.params.thegroupid.disabled = true;
    document.params.theuserid.disabled = true;
    <%
    }
  }
  else
  {
    %>
    document.params.thegroupid.disabled = true;
    document.params.theuserid.disabled = true
    <%
  }
  %>
    if ((document.pccodechange.theentitytype.value == "p") ||
        (document.pccodechange.theentitytype.value == "to") ||
        (document.pccodechange.theentitytype.value == "so"))
    {
        document.pccodechange.thegroupid.disabled = true;
    <%--[SCRIPT]  document.params.theuserid.disabled = true;  [SCRIPT]--%>
    }
</script>

</table>
</form>
</body>
</html>


